from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime
from decimal import Decimal


class UserBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    openid: str = Field(..., max_length=255, description="用户标识")
    unionid: Optional[str] = Field(None, max_length=255, description="联合用户标识")
    nickname: Optional[str] = Field(None, max_length=255, description="用户昵称 可保存特殊符号")
    headimg: Optional[str] = Field(None, max_length=255, description="用户头像")
    name: Optional[str] = Field(None, max_length=50, description="用户姓名")
    phone: Optional[str] = Field(None, max_length=11, description="手机号", pattern=r"^\d{11}$")
    gradeid: Optional[int] = Field(None, ge=0, description="选择年级ID")
    classid: Optional[int] = Field(None, ge=0, description="参加班级的ID")
    groupid: Optional[int] = Field(None, ge=0, description="群组ID")
    nativeplace: Optional[str] = Field(None, max_length=255, description="籍贯")
    province: Optional[str] = Field(None, max_length=255, description="省")
    city: Optional[str] = Field(None, max_length=255, description="市")
    county: Optional[str] = Field(None, max_length=255, description="县")
    ismember: Optional[int] = Field(2, ge=1, le=2, description="是否是会员  1 是会员 2不是，默认为2")
    password: Optional[str] = Field(None, max_length=255, description="用户登录密码")
    member_endtime: Optional[str] = Field(None, max_length=255, description="会员到期时间")
    status: Optional[int] = Field(1, ge=0, le=1, description="是否拉黑，默认为1")
    last_login_time: int = Field(..., description="最近一次登录时间，Unix 时间戳")
    integral: Optional[int] = Field(0, ge=0, description="用户积分数，默认为0")
    balance: Optional[Decimal] = Field(Decimal('0.00'), ge=0, description="用户余额，默认为0.00")
    qrcode: Optional[str] = Field(None, max_length=255, description="用户二维码路径")
    pid: Optional[int] = Field(0, ge=0, description="用户自己注册 为0  扫描其他人二维码 为二维码人的ID，默认为0")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="是否删除的标识，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    id_card: Optional[str] = Field(None, max_length=255, description="身份证号")
    student_id: Optional[str] = Field(None, max_length=200, description="学号")
    school: Optional[str] = Field(None, max_length=255, description="学校")
    level: Optional[int] = Field(0, ge=0, description="用户等级，默认为0")
    grade: Optional[str] = Field(None, max_length=255, description="年级")
    count_day: Optional[int] = Field(0, ge=0, description="累计天数，默认为0")
    is_band: int = Field(0, ge=0, le=1, description="是否绑定微信 1是0否，默认为0")
    h5_openid: str = Field(..., max_length=255, description="H5 用户标识")

    class Config:
        orm_mode = True


class UserCreate(UserBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserUpdate(UserBase):
    weid: Optional[int] = None
    openid: Optional[str] = None
    unionid: Optional[str] = None
    nickname: Optional[str] = None
    headimg: Optional[str] = None
    name: Optional[str] = None
    phone: Optional[str] = None
    gradeid: Optional[int] = None
    classid: Optional[int] = None
    groupid: Optional[int] = None
    nativeplace: Optional[str] = None
    province: Optional[str] = None
    city: Optional[str] = None
    county: Optional[str] = None
    ismember: Optional[int] = None
    password: Optional[str] = None
    member_endtime: Optional[str] = None
    status: Optional[int] = None
    last_login_time: Optional[int] = None
    integral: Optional[int] = None
    balance: Optional[Decimal] = None
    qrcode: Optional[str] = None
    pid: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    id_card: Optional[str] = None
    student_id: Optional[str] = None
    school: Optional[str] = None
    level: Optional[int] = None
    grade: Optional[str] = None
    count_day: Optional[int] = None
    is_band: Optional[int] = None
    h5_openid: Optional[str] = None


class UserInDB(UserBase):
    id: int
    last_login_time: Optional[datetime] = Field(None, description="最近一次登录时间")
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.last_login_time, int):
            obj.last_login_time = datetime.fromtimestamp(obj.last_login_time)
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserResponse(UserInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserListResponse(BaseModel):
    data: List[UserResponse]


class UserCollectionPractionBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    testid: int = Field(..., ge=0, description="试题ID")
    test_type: int = Field(..., ge=0, le=255, description="试题类型")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    iscollect: Optional[int] = Field(2, ge=0, le=2, description="是否收藏 1是 2不是，默认为2")

    class Config:
        orm_mode = True


class UserCollectionPractionCreate(UserCollectionPractionBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserCollectionPractionUpdate(UserCollectionPractionBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    testid: Optional[int] = None
    test_type: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    iscollect: Optional[int] = None


class UserCollectionPractionInDB(UserCollectionPractionBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserCollectionPractionResponse(UserCollectionPractionInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserCollectionPractionListResponse(BaseModel):
    data: List[UserCollectionPractionResponse]


class UserDoexamBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    examid: int = Field(..., ge=0, description="已发布的试卷、考试或练习的ID")
    franction: Optional[int] = Field(0, ge=0, description="得分情况，默认为0")
    usetime: str = Field('0', max_length=20, description="考试用时，默认为'0'")
    level: Optional[str] = Field(None, max_length=255, description="级别")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="交卷时间，Unix 时间戳")
    recordid: int = Field(..., ge=0, description="考试记录id")
    evaluation: int = Field(2, ge=1, le=3, description="评阅状态 1已评2未评默认2 3批改中")

    class Config:
        orm_mode = True


class UserDoexamCreate(UserDoexamBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserDoexamUpdate(UserDoexamBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    examid: Optional[int] = None
    franction: Optional[int] = None
    usetime: Optional[str] = None
    level: Optional[str] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    recordid: Optional[int] = None
    evaluation: Optional[int] = None


class UserDoexamInDB(UserDoexamBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="交卷时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserDoexamResponse(UserDoexamInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserDoexamListResponse(BaseModel):
    data: List[UserDoexamResponse]


class UserDoOtherExamBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    recordid: int = Field(..., ge=0, description="区分是哪一次考试的记录ID")
    franction: Optional[int] = Field(0, ge=0, description="得分情况，默认为0")
    usetime: str = Field('0', max_length=20, description="考试用时，默认为'0'")
    level: Optional[str] = Field(None, max_length=255, description="级别")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="交卷时间，Unix 时间戳")
    type: Optional[int] = Field(None, ge=2, le=3, description="类型 2-优先未做 3-智能考试")

    class Config:
        orm_mode = True


class UserDoOtherExamCreate(UserDoOtherExamBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserDoOtherExamUpdate(UserDoOtherExamBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    recordid: Optional[int] = None
    franction: Optional[int] = None
    usetime: Optional[str] = None
    level: Optional[str] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    type: Optional[int] = None


class UserDoOtherExamInDB(UserDoOtherExamBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="交卷时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserDoOtherExamResponse(UserDoOtherExamInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserDoOtherExamListResponse(BaseModel):
    data: List[UserDoOtherExamResponse]


class UserDoOtherExamAnswerBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    recordid: int = Field(..., ge=0, description="区分是哪一次考试的记录ID")
    testid: int = Field(..., ge=0, description="试题ID")
    test_type: int = Field(..., ge=0, le=255, description="试题类型")
    uanswer: Optional[str] = Field(None, description="用户答案")
    franction: Optional[int] = Field(0, ge=0, description="得分情况，默认为0")
    isright: int = Field(..., ge=0, le=1, description="是否正确")
    ischeck: Optional[int] = Field(1, ge=0, le=1, description="是否批改 默认为已批改")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    type: Optional[int] = Field(None, ge=2, le=3, description="类型 2-优先未做 3-智能考试")

    class Config:
        orm_mode = True


class UserDoOtherExamAnswerCreate(UserDoOtherExamAnswerBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserDoOtherExamAnswerUpdate(UserDoOtherExamAnswerBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    recordid: Optional[int] = None
    testid: Optional[int] = None
    test_type: Optional[int] = None
    uanswer: Optional[str] = None
    franction: Optional[int] = None
    isright: Optional[int] = None
    ischeck: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    type: Optional[int] = None


class UserDoOtherExamAnswerInDB(UserDoOtherExamAnswerBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserDoOtherExamAnswerResponse(UserDoOtherExamAnswerInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserDoOtherExamAnswerListResponse(BaseModel):
    data: List[UserDoOtherExamAnswerResponse]


class UserExamAnswerBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    examid: int = Field(..., ge=0, description="已发布的试卷、考试或练习的ID")
    testid: int = Field(..., ge=0, description="试题ID")
    test_type: int = Field(..., ge=0, le=255, description="试题类型")
    uanswer: Optional[str] = Field(None, description="用户答案")
    franction: Optional[int] = Field(0, ge=0, description="得分情况，默认为0")
    isright: int = Field(..., ge=0, le=1, description="是否正确")
    ischeck: Optional[int] = Field(1, ge=0, le=1, description="是否批改 默认为已批改")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    recordid: Optional[int] = Field(None, ge=0, description="考试记录id")
    type: Optional[int] = Field(None, ge=1, le=1, description="类型只有1-全真")
    simple_score: Optional[int] = Field(None, ge=0, description="简答题评分")
    comments: str = Field(..., description="简答题评语")
    simple_evaluation: int = Field(2, ge=1, le=3, description="简答题评阅状态 1已批改默认2未3批改中")

    class Config:
        orm_mode = True


class UserExamAnswerCreate(UserExamAnswerBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserExamAnswerUpdate(UserExamAnswerBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    examid: Optional[int] = None
    testid: Optional[int] = None
    test_type: Optional[int] = None
    uanswer: Optional[str] = None
    franction: Optional[int] = None
    isright: Optional[int] = None
    ischeck: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    recordid: Optional[int] = None
    type: Optional[int] = None
    simple_score: Optional[int] = None
    comments: Optional[str] = None
    simple_evaluation: Optional[int] = None


class UserExamAnswerInDB(UserExamAnswerBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserExamAnswerResponse(UserExamAnswerInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserExamAnswerListResponse(BaseModel):
    data: List[UserExamAnswerResponse]


class UserFormidBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    formid: str = Field(..., max_length=255, description="表单ID")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserFormidCreate(UserFormidBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserFormidUpdate(UserFormidBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    formid: Optional[str] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None


class UserFormidInDB(UserFormidBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserFormidResponse(UserFormidInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserFormidListResponse(BaseModel):
    data: List[UserFormidResponse]


class UserGiftBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    giftid: int = Field(..., ge=0, description="礼品ID")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    status: Optional[int] = Field(0, ge=0, le=255, description="状态，默认为0")
    updatetime: Optional[int] = Field(None, description="更新时间，Unix 时间戳")
    consignee_name: Optional[str] = Field(None, max_length=255, description="收货人姓名")
    consignee_phone: Optional[str] = Field(None, max_length=255, description="收货人电话")
    consignee_address: Optional[str] = Field(None, max_length=255, description="收货人地址")

    class Config:
        orm_mode = True


class UserGiftCreate(UserGiftBase):
    pass  # 如果创建时需要额外字段或默认值不同，可以在这里添加


class UserGiftUpdate(UserGiftBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    giftid: Optional[int] = None
    createtime: Optional[int] = None
    status: Optional[int] = None
    updatetime: Optional[int] = None
    consignee_name: Optional[str] = None
    consignee_phone: Optional[str] = None
    consignee_address: Optional[str] = None


class UserGiftInDB(UserGiftBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")
    updatetime: Optional[datetime] = Field(None, description="更新时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        if isinstance(obj.updatetime, int) and obj.updatetime is not None:
            obj.updatetime = datetime.fromtimestamp(obj.updatetime)
        return super().from_orm(obj)

    class Config:
        orm_mode = True


class UserGiftResponse(UserGiftInDB):
    pass  # 可以根据需要添加额外的字段或调整现有字段


# 用于批量操作的模型
class UserGiftListResponse(BaseModel):
    data: List[UserGiftResponse]


class UserKnowledgeCateBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(0, ge=0, description="用户ID")
    cate: Optional[int] = Field(0, ge=0, description="知识点ID")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="是否删除的标识，默认为1")

    class Config:
        orm_mode = True


class UserKnowledgeCateCreate(UserKnowledgeCateBase):
    pass


class UserKnowledgeCateUpdate(UserKnowledgeCateBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    cate: Optional[int] = None
    createtime: Optional[int] = None
    istatus: Optional[int] = None


class UserKnowledgeCateInDB(UserKnowledgeCateBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserKnowledgeCateResponse(UserKnowledgeCateInDB):
    pass


class UserKnowledgeCateListResponse(BaseModel):
    data: List[UserKnowledgeCateResponse]


class UserMemberBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    status: Optional[int] = Field(2, ge=0, le=2, description="是否开启购买会员，默认为2")
    scale: Decimal = Field(Decimal('1.00'), ge=0, le=1, description="折扣比例，默认为1.00")
    info: Optional[str] = Field(None, description="详细信息")
    price: Decimal = Field(Decimal('0.00'), ge=0, description="VIP单月价格，默认为0.00")
    istui: Optional[int] = Field(0, ge=0, description="推荐购买的，默认为0")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserMemberCreate(UserMemberBase):
    pass


class UserMemberUpdate(UserMemberBase):
    weid: Optional[int] = None
    status: Optional[int] = None
    scale: Optional[Decimal] = None
    info: Optional[str] = None
    price: Optional[Decimal] = None
    istui: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None


class UserMemberInDB(UserMemberBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserMemberResponse(UserMemberInDB):
    pass


class UserMemberListResponse(BaseModel):
    data: List[UserMemberResponse]


class UserPoolBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(0, ge=0, description="用户ID")
    poolid: Optional[int] = Field(0, ge=0, description="题库ID")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="是否删除的标识，默认为1")
    paperid: int = Field(0, ge=0, description="试卷id")

    class Config:
        orm_mode = True


class UserPoolCreate(UserPoolBase):
    pass


class UserPoolUpdate(UserPoolBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    poolid: Optional[int] = None
    createtime: Optional[int] = None
    istatus: Optional[int] = None
    paperid: Optional[int] = None


class UserPoolInDB(UserPoolBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserPoolResponse(UserPoolInDB):
    pass


class UserPoolListResponse(BaseModel):
    data: List[UserPoolResponse]


class UserQHighBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    user_id: int = Field(..., ge=0, description="用户ID")
    question_id: int = Field(..., ge=0, description="试题ID")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    create_time: int = Field(..., description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserQHighCreate(UserQHighBase):
    pass


class UserQHighUpdate(UserQHighBase):
    weid: Optional[int] = None
    user_id: Optional[int] = None
    question_id: Optional[int] = None
    istatus: Optional[int] = None
    create_time: Optional[int] = None


class UserQHighInDB(UserQHighBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.create_time, int):
            obj.create_time = datetime.fromtimestamp(obj.create_time)
        return super().from_orm(obj)


class UserQHighResponse(UserQHighInDB):
    pass


class UserQHighListResponse(BaseModel):
    data: List[UserQHighResponse]


class UserQIntensiveBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    user_id: int = Field(..., ge=0, description="用户ID")
    question_id: int = Field(..., ge=0, description="试题ID")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    create_time: int = Field(..., description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserQIntensiveCreate(UserQIntensiveBase):
    pass


class UserQIntensiveUpdate(UserQIntensiveBase):
    weid: Optional[int] = None
    user_id: Optional[int] = None
    question_id: Optional[int] = None
    istatus: Optional[int] = None
    create_time: Optional[int] = None


class UserQIntensiveInDB(UserQIntensiveBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.create_time, int):
            obj.create_time = datetime.fromtimestamp(obj.create_time)
        return super().from_orm(obj)


class UserQIntensiveResponse(UserQIntensiveInDB):
    pass


class UserQIntensiveListResponse(BaseModel):
    data: List[UserQIntensiveResponse]


class UserQTypeBase(BaseModel):
    weid: Optional[int] = Field(0, ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    type_id: int = Field(..., ge=0, description="题型ID")
    last_id: Optional[int] = Field(None, ge=0, description="最后退出时的题目ID")
    istatus: Optional[int] = Field(1, ge=0, le=255, description="删除状态，默认为1")
    createtime: Optional[int] = Field(None, description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserQTypeCreate(UserQTypeBase):
    pass


class UserQTypeUpdate(UserQTypeBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    type_id: Optional[int] = None
    last_id: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None


class UserQTypeInDB(UserQTypeBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int) and obj.createtime is not None:
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserQTypeResponse(UserQTypeInDB):
    pass


class UserQTypeListResponse(BaseModel):
    data: List[UserQTypeResponse]


class UserReadBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    noticeid: int = Field(..., ge=0, description="公告/活动/文章ID")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserReadCreate(UserReadBase):
    pass


class UserReadUpdate(UserReadBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    noticeid: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None


class UserReadInDB(UserReadBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserReadResponse(UserReadInDB):
    pass


class UserReadListResponse(BaseModel):
    data: List[UserReadResponse]


class UserSpecialBase(BaseModel):
    weid: Optional[int] = Field(0, ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    special_id: int = Field(..., ge=0, description="特殊ID")
    last_id: Optional[int] = Field(None, ge=0, description="最后退出时的题目ID")
    istatus: Optional[int] = Field(1, ge=0, le=255, description="删除状态，默认为1")
    createtime: Optional[int] = Field(None, description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserSpecialCreate(UserSpecialBase):
    pass


class UserSpecialUpdate(UserSpecialBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    special_id: Optional[int] = None
    last_id: Optional[int] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None


class UserSpecialInDB(UserSpecialBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int) and obj.createtime is not None:
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserSpecialResponse(UserSpecialInDB):
    pass


class UserSpecialListResponse(BaseModel):
    data: List[UserSpecialResponse]


class UserSpequenceBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    user_id: int = Field(..., ge=0, description="用户ID")
    question_id: int = Field(..., ge=0, description="下标ID，这儿是顺序id")
    lib_id: Optional[int] = Field(None, ge=0, description="题库id")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    create_time: int = Field(..., description="创建时间，Unix 时间戳")

    class Config:
        orm_mode = True


class UserSpequenceCreate(UserSpequenceBase):
    pass


class UserSpequenceUpdate(UserSpequenceBase):
    weid: Optional[int] = None
    user_id: Optional[int] = None
    question_id: Optional[int] = None
    lib_id: Optional[int] = None
    istatus: Optional[int] = None
    create_time: Optional[int] = None


class UserSpequenceInDB(UserSpequenceBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.create_time, int):
            obj.create_time = datetime.fromtimestamp(obj.create_time)
        return super().from_orm(obj)


class UserSpequenceResponse(UserSpequenceInDB):
    pass


class UserSpequenceListResponse(BaseModel):
    data: List[UserSpequenceResponse]


class UserWrongPractionBase(BaseModel):
    weid: int = Field(..., ge=0, description="站点 ID")
    uid: int = Field(..., ge=0, description="用户ID")
    testid: int = Field(..., ge=0, description="试题ID")
    test_type: int = Field(..., ge=0, le=255, description="试题类型")
    uanswer: Optional[str] = Field(None, description="用户答案")
    istatus: Optional[int] = Field(1, ge=0, le=1, description="删除状态，默认为1")
    createtime: int = Field(..., description="创建时间，Unix 时间戳")
    iscollect: Optional[int] = Field(2, ge=0, le=2, description="是否收藏，默认为2")

    class Config:
        orm_mode = True


class UserWrongPractionCreate(UserWrongPractionBase):
    pass


class UserWrongPractionUpdate(UserWrongPractionBase):
    weid: Optional[int] = None
    uid: Optional[int] = None
    testid: Optional[int] = None
    test_type: Optional[int] = None
    uanswer: Optional[str] = None
    istatus: Optional[int] = None
    createtime: Optional[int] = None
    iscollect: Optional[int] = None


class UserWrongPractionInDB(UserWrongPractionBase):
    id: int
    createtime: Optional[datetime] = Field(None, description="创建时间")

    @classmethod
    def from_orm(cls, obj):
        if isinstance(obj.createtime, int):
            obj.createtime = datetime.fromtimestamp(obj.createtime)
        return super().from_orm(obj)


class UserWrongPractionResponse(UserWrongPractionInDB):
    pass


class UserWrongPractionListResponse(BaseModel):
    data: List[UserWrongPractionResponse]
